package com.sunspring.jbug.controller;

import com.sunspring.jbug.bean.UserInfo;
import com.sunspring.jbug.common.RoleEnum;
import com.sunspring.jbug.common.SimpleResponse;
import com.sunspring.jbug.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wulei
 * @date 2019-02-27
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 查询所有用户
     */
    @GetMapping("/info")
    public SimpleResponse info() {
        return SimpleResponse.success(userService.getSelective(new UserInfo()));
    }

    /**
     * 所有测试人员
     */
    @GetMapping("/testMan")
    public SimpleResponse testMan() {
        UserInfo userInfo = new UserInfo();
        userInfo.setRole(RoleEnum.SUBMITTER.getCode());
        return SimpleResponse.success(userService.getSelective(userInfo));
    }


    /**
     * 所有开发人员
     */
    @GetMapping("/developer")
    public SimpleResponse developer() {
        UserInfo userInfo = new UserInfo();
        userInfo.setRole(RoleEnum.RESTORER.getCode());
        return SimpleResponse.success(userService.getSelective(userInfo));
    }


    @PostMapping("/add")
    public SimpleResponse add(UserInfo userInfo) {
        userService.add(userInfo);
        return SimpleResponse.success();
    }

}
